package com.joshondesign.sdljava.gfx.effects;

/**
* Created by IntelliJ IDEA.
* User: josh
* Date: 9/14/11
* Time: 2:30 AM
* To change this template use File | Settings | File Templates.
*/
public class BrightnessFilter extends ImageFilter {

    private double value = 0.0;

    public long[] apply(long r, long g, long b, long a) {
        int adj = (int) (value*255.0);
        r = clamp(0,r + adj,255);
        g = clamp(0,g + adj,255);
        b = clamp(0,b + adj,255);
        //a = clamp(0,a+adj,255);
        return new long[]{r,g,b,a};
    }

    private long clamp(int min, long value, int max) {
        if(value<min) return min;
        if(value>max) return max;
        return value;
    }

    public void setValue(double value) {
        this.value = value;
        this.dirty = true;
    }

}
